package com.blogSystem.article.util;


import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeDifference {
  public static String count(Date time){
    Date now=new Date();
    long between= now.getTime()-time.getTime();
    SimpleDateFormat sf=new SimpleDateFormat("yy-MM-dd");
    long day = between / (24 * 60 * 60 * 1000);
    long hour = (between / (60 * 60 * 1000) - day * 24);
    long min = ((between / (60 * 1000)) - day * 24 * 60 - hour * 60);
    long s = (between / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
    long ms = (between - day * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000                - min * 60 * 1000 - s * 1000);
    String timeDifference = day + "天" + hour + "小时" + min + "分" + s + "秒" + ms                + "毫秒";
    if(day>3){
      return sf.format(time);
    }
    else if(day>0){
      return day+"天前";
    }
    else if (hour>0){
      return hour+"小时前";
    }
    else if(min>0){
      return min+"分钟前";
    }
    else{
      return s+"秒前";
    }
  }
}
